package com.test.definition;

import com.test.value.PropertyValues;

/**
 * Bean定义类，用于描述Bean的元数据
 * 包含了Bean的类信息、属性值、初始化和销毁方法等配置
 */
public class BeanDefinition {
    // Bean对应的类
    private Class<?> beanClass;

    // Bean的属性值集合
    private PropertyValues propertyValues = new PropertyValues();

    // Bean的初始化方法名
    private String initMethodName;

    // Bean的销毁方法名
    private String destroyMethodName;

    // 是否为单例模式，默认是单例
    private boolean singleton = true;

    // 是否为原型模式，默认不是原型
    private boolean prototype = false;



    // 单例模式的常量表示
    public static String SCOPE_SINGLETON = "singleton";

    // 原型模式的常量表示
    public static String SCOPE_PROTOTYPE = "prototype";

    public BeanDefinition(Class<?> beanClass) {
        this.beanClass = beanClass;
    }
    public BeanDefinition(Class<?> beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }

    public Class<?> getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    public String getDestroyMethodName() {
        return destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }

    public String getInitMethodName() {
        return initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

    public boolean isPrototype() {
        return prototype;
    }

    public void setPrototype(boolean prototype) {
        this.prototype = prototype;
    }

    public boolean isSingleton() {
        return singleton;
    }

    public void setSingleton(boolean singleton) {
        this.singleton = singleton;
    }

    public void setScope(String scope) {
        if (SCOPE_SINGLETON.equals(scope)) {
            this.singleton = true;
            this.prototype = false;
        } else if (SCOPE_PROTOTYPE.equals(scope)) {
            this.singleton = false;
            this.prototype = true;
        } else {
            throw new IllegalArgumentException("非法的scope值：" + scope);
        }
    }
}
